package com.clouddot.baipai.ui.Dialog;

import android.app.Dialog;
import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.support.v7.widget.DefaultItemAnimator;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.clouddot.baipai.R;
import com.clouddot.baipai.contract.IH_SMainActivityContract;
import com.clouddot.baipai.http.entity.response.getIndexListResponse;
import com.clouddot.baipai.infrastructure.environment.Env;
import com.clouddot.baipai.ui.adapter.H_EvaluateAdapter;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by wxy on 2018/4/2.
 */

public class A_EvaluateDailog {
    private Dialog Dialog;
    private ConstraintLayout constraintLayout;
    private Context context;
    private View view;
    private List<getIndexListResponse.IndexInfo> mDataList = new ArrayList<>();
    private H_EvaluateAdapter adapter;
    private RecyclerView recyclerView;
    private ImageView close;
    private TextView tvSummit;

    public A_EvaluateDailog(Context context ,List<getIndexListResponse.IndexInfo> mDataList) {
        this.context = context;
        this.mDataList = mDataList;
        initView();

    }

    public ImageView getImgClose(){
        if(close == null){
            close = constraintLayout.findViewById(R.id.close);
        }
        return close;
    }

    public TextView getTvSummit(){
        if(tvSummit == null){
            tvSummit = constraintLayout.findViewById(R.id.tvSummit);
        }
        return tvSummit;
    }

    public List<getIndexListResponse.IndexInfo>  getmDataList(){
        return mDataList;
    }

    private void initView() {
        constraintLayout = (ConstraintLayout) LayoutInflater.from(context).inflate(R.layout.h_dialog_evaluate, null);
        recyclerView = constraintLayout.findViewById(R.id.recyclerView);
        LinearLayoutManager mLayoutManager = new LinearLayoutManager(context);
        recyclerView.setLayoutManager(mLayoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        for(getIndexListResponse.IndexInfo indexInfo : mDataList ){
            if(indexInfo.Fraction > 0){
                getTvSummit().setVisibility(View.GONE);
                break;
            }else{
                getTvSummit().setVisibility(View.VISIBLE);
            }
        }
        adapter = new H_EvaluateAdapter(context,mDataList);
        recyclerView.setAdapter(adapter);
    }

    public void showDialog() {

        Dialog = getDialog();
        Dialog.show();

    }

    public void closeDialog() {
        if (Dialog != null) {
            Dialog.dismiss();
        }
    }

    public Dialog getDialog() {
        if (Dialog == null) {
            Dialog = new Dialog(context, R.style.ActionDialogStyle);
        }

        Dialog.setContentView(constraintLayout);

        Window dialogWindow = Dialog.getWindow();
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.MATCH_PARENT;
        dialogWindow.setAttributes(lp);
        view = dialogWindow.getDecorView();
        lock();

        view.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int i) {
                lock();
            }
        });

        Dialog.setCancelable(false);

        return Dialog;
    }

    private void lock() {
        int uiFlags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE;
        view.setSystemUiVisibility(uiFlags);
    }




}



